﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConceptsParser.ParserTools
{
    /// <summary>
    /// Вспомогательные инструменты для парсера
    /// </summary>
    public class ParserToolsManager
    {
        public static string LexLocation_ToString(QUT.Gppg.LexLocation location)
        {
            return String.Format("Строка {0}, позиция {1} [до ({2}, {3})]",
                location.StartLine, location.StartColumn, 
                location.EndLine, location.EndColumn);
        }

        private LinkedList<SyntaxError> syntaxErrors = new LinkedList<SyntaxError>();

        public bool HasSyntaxErrors
        {
            get { return syntaxErrors.Count > 0; }
        }

        public SyntaxError FirstSyntaxError
        {
            get 
            {
                return (syntaxErrors.Count == 0) 
                    ? null 
                    : syntaxErrors.First.Value;
            }
        }

        public ParserToolsManager() { }

        public void AddSyntaxError(SyntaxError error) 
        {
            if (error == null)
                throw new ArgumentNullException("error can not be null");
            syntaxErrors.AddLast(error);
        }
    }

    
}
